package com.wangjw.springbootdemo.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by wangjw on 18/5/30.
 */
@Component
public class TestTask {

    private static final Logger logger = LoggerFactory.getLogger(TestTask.class);

    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");

    // 每隔3s执行一次
    @Scheduled(fixedRate = 3000)
    public void reportCurrentTime1() {
        try {
            Thread.sleep(5000);
            logger.info("当前时间1：{}", dateFormat.format(new Date()));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    // 每隔3s执行一次
    @Scheduled(fixedRate = 3000)
    public void reportCurrentTime3() {
        logger.info("当前时间2：{}", dateFormat.format(new Date()));
    }
}
